<?php
error_reporting(E_ALL);
define(PJAX, !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');

$scripts = [
	'/js/admin.js'
	];

$data = [
	'title'=>'admin page',
	'url'=>'/admin/',
	'content' => <<<EOF
<form class="full" action="ajax_post.php" enctype="multipart/form-data" method="post">
	<label for="form_title">Title</label>
	<input id="form_title" name="title"/>
	<label for="form_link">Link</label>
	<input id="form_link" name="link" />
	<label for="form_col">Cols</label>
	<select name="col" id="form_col">
		<option value="1">1</option>
		<option value="2">2</option>
		<option value="3">3</option>
	</select>
	<label for="form_image">Image</label>
	<input name="image" id="form_image" type="file" />
	<textarea class="full" name="content"></textarea>
	<input type="submit"/>
</form>
EOF
,
	];

foreach($scripts as $src){
	$data['content'] .= '<script src="'.$src.'" type="text/javascript" charset="utf-8"></script>';
}
if(PJAX){
	header("Content-Type: application/json");
	echo json_encode($data);
}else{
	echo <<<EOF
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="content-type" content="text/html; charset=utf-8" />
		<link rel="stylesheet" href="/css/common.css" type="text/css" charset="utf-8">
		<link rel="stylesheet" href="/css/index.css" type="text/css" charset="utf-8">
		<script src="/js/jquery-1.8.3.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="/js/jquery.masonry.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="/js/jquery.form.js" type="text/javascript" charset="utf-8"></script>
		<script src="/js/common.js" type="text/javascript" charset="utf-8"></script>
		<title>TODO:Index</title>
	</head>
	<body>
		<header>
			<h1>Kai6's website</h1>
			<nav class="right middletext"><ul class="list-horizontal">
				<li><a href="http://kjwon15.tistory.com/">Blog</a></li>
				<li><a href="http://kjwon15.netii.net/">Website</a></li>
				<li><a href="/admin/">Admin</a></li>
			</ul></nav>
			<div class="clearfix"></div>
		</header>
		<div class="container">
			{$data['content']}
		</div>
		<footer class="right">
		<p>Copyright&copy; Kjwon15 All rights reserved.
		<br />Mail: <a href="mailto:kjwonmail@gmail.com">kjwonmail@gmail.com</a></p>
		</footer>
	</body>
</html>
EOF;
}
